package com.xuxueli.applyModules.service;
import com.alibaba.excel.EasyExcel;
import com.xuxueli.applyModules.exception.ErrorException;
import com.xuxueli.applyModules.listener.EasyExcelListener;
import com.xuxueli.applyModules.entity.DemoExcel;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.BufferedInputStream;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class UploadService {

    public void importExcelCourier(MultipartFile file){
        //excel读取数据
        List<DemoExcel> excelList;
        try {
            excelList = EasyExcel.read(new BufferedInputStream(file.getInputStream()), DemoExcel.class, new EasyExcelListener()).sheet().doReadSync();
        } catch (Exception e) {
            throw new ErrorException(500,e.getCause().getMessage());
        }
        //stream流去重
        List<DemoExcel> distinctList = excelList.stream().distinct().collect(Collectors.toList());
        //拿到数据后就可以 入库操作啦 -----我自己的入库就不给你们写了
    }

}
